package com.kcsoft.welcome.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kcsoft.welcome.mapper.NewMemMapper;
import com.kcsoft.welcome.pojo.NewMem;
import com.kcsoft.welcome.pojo.PageBean;
import com.kcsoft.welcome.service.NewMemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewMemServiceImpl implements NewMemService {

    @Autowired
    NewMemMapper newMemMapper;

    @Override
    public void add(NewMem newMem) {
        newMemMapper.add(newMem);
    }

    @Override
    public PageBean<NewMem> list(Integer pageNum, Integer pageSize) {
        PageBean<NewMem> pb = new PageBean<>();

        PageHelper.startPage(pageNum, pageSize);

        List<NewMem> nl = newMemMapper.list();

        Page<NewMem> np = (Page<NewMem>) nl;

        pb.setTotal(np.getTotal());

        pb.setItems(np.getResult());

        return pb;
    }

    @Override
    public void deleteAll() {
        newMemMapper.deleteAll();
    }
}
